﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using DrugStorehouseMIS.Comm;
using DrugStorehouseMIS.DAL.Interface;


namespace DrugStorehouseMIS.DAL
{
    public class DrugTypeDAL:IDrugTypeDAL
    {

        #region IDrugTypeDAL 成员

        public IDataReader Select()
        {
            try
            {
                return SqlDbHelper.RunProcedure_Reader(ConnectionString.ConnString, "Proc_DrugType_Select_All");
            }
            catch (Exception ex)
            {
                EventLog.WriteErrorLog(ex.Message);
                throw;
            }
        }

        public IDataReader Select(int DrugTypeNum)
        {
            try
            {
                return SqlDbHelper.RunProcedure_Reader(ConnectionString.ConnString, "Proc_DrugType_Select", new SqlParameter[] { new SqlParameter("@DrugTypeNum", DrugTypeNum) });
            }
            catch (Exception ex)
            {
                EventLog.WriteErrorLog(ex.Message);
                throw;
            }
        }

        public IDataReader Select(string DrugTypeName)
        {
            try
            {
                return SqlDbHelper.RunProcedure_Reader(ConnectionString.ConnString, "Proc_DrugType_Select_By_Name", new SqlParameter[] { new SqlParameter("@DrugTypeName", DrugTypeName) });
            }
            catch (Exception ex)
            {
                EventLog.WriteErrorLog(ex.Message);
                throw;
            }
        }

        public DataTable SelectAll()
        {
            try
            {
                return SqlDbHelper.RunProcedure_DataTable(ConnectionString.ConnString, "Proc_DrugType_Select_All");
            }
            catch (Exception ex)
            {
                EventLog.WriteErrorLog(ex.Message);
                throw;
            }
        }

        public int Insert(string DrugTypeName, string DrugTypeCode)
        {
            try
            {
                SqlParameter[] all = new SqlParameter[]
                {
                    new SqlParameter("@DrugTypeName",DrugTypeName),
                    new SqlParameter("@DrugTypeCode",DrugTypeCode)
                };
                return SqlDbHelper.RunProcedure_Query(ConnectionString.ConnString, "Proc_DrugType_Insert", all);
            }
            catch (Exception ex)
            {
                 EventLog.WriteErrorLog(ex.Message);
                throw;
            }
        }

        public int Update(int DrugTypeNum, string DrugTypeName, string DrugTypeCode)
        {
            try
            {
                SqlParameter[] all = new SqlParameter[]
                {
                    new SqlParameter("@DrugTypeNum",DrugTypeNum),
                    new SqlParameter("@DrugTypeName",DrugTypeName),
                    new SqlParameter("@DrugTypeCode",DrugTypeCode)
                };
                return SqlDbHelper.RunProcedure_Query(ConnectionString.ConnString, "Proc_DrugType_Update", all);
            }
            catch (Exception ex)
            {
                EventLog.WriteErrorLog(ex.Message);
                throw;
            }
        }

        public int Delete(int DrugTypeNum)
        {
            try
            {
                return SqlDbHelper.RunProcedure_Query(ConnectionString.ConnString, "Proc_DrugType_Delete", new SqlParameter[] { new SqlParameter("@DrugTypeNum", DrugTypeNum) });
            }
            catch (Exception ex)
            {
                EventLog.WriteErrorLog(ex.Message);
                throw;
            }
        }

        #endregion
    }
}
